<?php
class news {
	private $id;
	private $title;
	private $description;
	private $content;
	private $url_rewrite;
	private $image;
	private $status;
	private $date;
	private $cat_id;
	
	// set get id
	public function setid($id) {
		$this->id = $id;
	}
	public function getid() {
		return $this->id;
	}
	// set get title
	public function settitle($title) {
		$this->title = $title;
	}
	public function gettitle() {
		return $this->title;
	}
	// set get description
	public function setdescription($description) {
		$this->description = $description;
	}
	public function getdescription() {
		return $this->description;
	}
	// set get content
	public function setcontent($content) {
		$this->content = $content;
	}
	public function getcontent() {
		return $this->content;
	}
	// set get url_rewrite
	public function seturl_rewrite($url_rewrite) {
		$this->url_rewrite = $url_rewrite;
	}
	public function geturl_rewrite() {
		return $this->url_rewrite;
	}
	// set get image
	public function setimage($image) {
		$this->image = $image;
	}
	public function getimage() {
		return $this->image;
	}
	// set get status
	public function setstatus($status) {
		$this->status = $status;
	}
	public function getstatus() {
		return $this->status;
	}
	// set get date
	public function setdate($date) {
		$this->date = $date;
	}
	public function getdate() {
		$date = ($this->date)?$this->date:time();
		return $date;
	}
	// set get date
	public function setcat_id($cat_id) {
		$this->cat_id = $cat_id;
	}
	public function getcat_id() {
		return $this->cat_id;
	}
	
	public function getone() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "news where id='" . $this->id . "'";
		$return = $db->executeQuery ( $sql, 2 );
		return $return;
	}
	public function listbycat() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "news where cat_id='".$this->getcat_id()."' order by date DESC";
		$result = $db->executeQuery ( $sql );
		while ( $rows = mysql_fetch_array ( $result ) ) {
			$return [] = $rows;
		}
		return $return;
	}
	public function listall() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "news";
		$result = $db->executeQuery ( $sql );
		while ( $rows = mysql_fetch_array ( $result ) ) {
			$return [] = $rows;
		}
		return $return;
	}
	public function delete() {
		GLOBAL $db;
		$sql = "DELETE FROM " . $db->tbl_fix . "news where `id` ='" . $this->id . "'";
		$db->executeQuery ( $sql );
	}
	public function insert(){
		GLOBAL $db;
		//$arr['id'] = $this->getid();
		$arr['title'] = $this->gettitle();
		$arr['description'] = $this->getdescription();
		$arr['content'] = $this->getcontent();
		$arr['image'] = $this->getimage();
//		$arr['image2'] = $this->getimage2();
//		$arr['image3'] = $this->getimage3();
		$arr['cat_id'] = $this->getcat_id();
		$arr['date'] = $this->getdate();
		$arr['status'] = $this->getstatus();
//		$arr['tinhtrang'] = $this->gettinhtrang();
//		$arr['banchay'] = $this->getbanchay();
//		$arr['tieubieu'] = $this->gettieubieu();
		$arr['url_rewrite'] = $this->geturl_rewrite();
//		print_r($arr);		
		$db->record_insert($db->tbl_fix."news", $arr);
	}
	public function update(){
		GLOBAL $db;
		$arr['title'] = $this->gettitle();
		$arr['description'] = $this->getdescription();
		$arr['content'] = $this->getcontent();
		$arr['image'] = $this->getimage();
		$arr['status'] = $this->getstatus();
		$arr['url_rewrite'] = $this->geturl_rewrite();
		$db->record_update($db->tbl_fix."news", $arr,"`id`='".$this->getid()."'");
	}

}
$news = new news();
?>